<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>出差列表</title>
<link rel="stylesheet" type="text/css" href="../Styles/admin-all.css" />
    <link rel="stylesheet" type="text/css" href="../Styles/base.css" />
    <link rel="stylesheet" type="text/css" href="../Styles/bootstrap-3.3.7-dist/css/bootstrap.min.css" />
	<link rel="stylesheet" type="text/css" href="../Styles/bootstrap-3.3.7-dist/css/bootstrap-theme.min.css" />
    <script type="text/javascript" src="../Scripts/jquery.min.js"></script>
    <script type="text/javascript" src="../Styles/bootstrap-3.3.7-dist/js/bootstrap.min.js"></script>
    <script type="text/javascript" src="../Styles\laypage\laypage.js"></script>
    <style type="text/css">
        #trip{
            width: 80%;
            height: 60%;
            margin: auto;
            margin-top: 30px;
        }
        #page{
        	float: right;
        }
    </style>
    <style type="text/css">
      #sp{
      	height: 500px;
      	width: 700px;
      	margin: auto;
      	margin-top: 30px;
      }
      #sps{
      	
      	text-align: center;
      	margin-top: 20px;
      }
    </style>
</head>
<body>

<div id="trip" class="view">
<input type="hidden" id="uid" value=""/>
    <h2 style="margin-bottom: 20px;background: oldlace;height: 50px;padding-top: 8px">出差管理</h2>
    <div id="tr">
        <form action="" class="form-search">
        	
            <div class="input-group" style="margin-bottom: 10px;width: 600px;float: right;">
                           
                <input id="inp" class="form-control" type="text" value="" placeholder="请输入申请人姓名或者审批状态"/>
                <span class="input-group-btn">
                	<button type="button" class="btn" id="btn">查找</button>
                </span>
                
            </div>
            
            <div>
            	<button type="button" class="btn btn-danger" data-toggle="modal" data-target="#deleModal">清理数据</button>
            	<select name="ckey" class="selectpicker show-tick form-control" style="width:120px;float: right;margin-right: 20px;" id="ex">
					<option value="0" selected="selected">请选择审批人</option>			
				</select>
            </div>
            
            <table class="table table-hover">
                <thead>
                    <tr class="info"><th colspan="9">出差申请列表</th></tr>
                    <tr class="info" align="left"><th><input type="checkbox" id="allChecked" name="allChecked" onclick="check_all()"/></th><th>序号</th><th>申请人</th><th>部门名称</th><th>申请时间</th><th>出差时间</th><th>状态</th><th>审批人</th><th>操作</th></tr>
                </thead>
                <tbody id="tr1">
                    
                </tbody>
            </table>
            <div id="page"></div>
        </form>
    </div>
    
    <!-- 模态框（Modal） -->
	<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
		<div class="modal-dialog">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal" aria-hidden="true">
						&times;
					</button>
					<h4 class="modal-title" id="myModalLabel">
						出差申请审批
					</h4>
				</div>
				<div class="modal-body">
					<form action="../showTr/updateTr">
						<input type="hidden" value="" class="tr_id" name="hid"/>
						<table class="table table-hover">
							<thead>
					        	<tr class="waning"><th colspan="3"><a href="../Template/showTrip.jsp">出差管理</a>>>申请审批</th><th><<<a href="../Template/showTrip.jsp">返回上一级</a></th></tr>
					        </thead>
					        <tbody>
					        	<tr><td class="info">申请人</td><td class="d1"></td><td class="info">部门名称</td><td class="d2"></td></tr>
								<tr><td class="success">工作任务</td><td class="d3"></td><td class="success">出差地点</td><td class="d4"></td></tr>
								<tr><td class="info">申请日期</td><td class="d6"></td><td class="info">开始日期</td><td class="d5"></td></tr>
								<tr><td class="success">陪同人</td><td colspan="3" class="d7"></td></tr>	
								<tr><td class="info">详细理由</td><td colspan="3" class="d8"></td></tr>			
					        </tbody>
							<tr id="sps"><td colspan="2"><input type="submit" class="btn" name="btn" value="审批通过"/></td><td colspan="2"><input type="submit" class="btn" name="btn" value="审批不通过"/></td></tr>
						</table>
					</form>
				</div>
			</div><!-- /.modal-content -->
		</div><!-- /.modal -->
	</div>
	
	<!-- 查看信息模态框 -->
	<div class="modal fade" id="selectTr" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
		<div class="modal-dialog">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal" aria-hidden="true">
						&times;
					</button>
					<h4 class="modal-title" id="myModalLabel">
						出差申请详细信息展示
					</h4>
				</div>
				<div class="modal-body">
					<form action="../showTr/updateTr">
						<input type="hidden" value="" class="tr_id" name="hid"/>
						<table class="table table-hover">
							<thead>
					        	<tr class="waning"><th colspan="3"><a href="../Template/showTrip.jsp">出差管理</a>>>申请审批</th><th><<<a href="../Template/showTrip.jsp">返回上一级</a></th></tr>
					        </thead>
					        <tbody>
					        	<tr><td class="info">申请人</td><td class="td1"></td><td class="info">部门名称</td><td class="td2"></td></tr>
								<tr><td class="success">工作任务</td><td class="td3"></td><td class="success">出差地点</td><td class="td4"></td></tr>
								<tr><td class="info">交通工具</td><td class="td6"></td><td class="info">申请日期</td><td class="td5"></td></tr>
								<tr><td class="success">陪同人</td><td colspan="1" class="td9"></td><td class="success">开始日期</td><td class="td7"></td></tr>
								<tr><td class="info">审批状态</td><td class="td11"></td><td class="info">结束日期</td><td class="td8"></td></tr>
								<tr><td class="success">详细理由</td><td colspan="3" class="td10"></td></tr>			
					        </tbody>
							
						</table>
					</form>
				</div>
			</div><!-- /.modal-content -->
		</div><!-- /.modal -->
	</div>
	
	<!-- 删除提示模态框 -->
	<div class="modal fade" id="deleteTr" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
		<div class="modal-dialog">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal" aria-hidden="true">
						&times;
					</button>
					<h4 class="modal-title" id="myModalLabel">
						删除提示框
					</h4>
				</div>
				<div class="modal-body">
					<span style="text-align:center;font-size: 20px">您确定删除此条申请吗？</span>
					<input type='hidden' value="" id='trid'/>
				</div>
				<div class="modal-footer">  
	                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>  
	                <button type="button" class="btn btn-primary" id="btn1">确定</button>  
	            </div> 
			</div><!-- /.modal-content -->
		</div><!-- /.modal -->
	</div>
	
	<!-- 删除模态框（Modal） -->
	<div class="modal fade" id="deleModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
		<div class="modal-dialog">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
					<h4 class="modal-title" id="myModalLabel">温馨提示</h4>
				</div>
				<div class="modal-body">您确定清理这些数据吗？？？？	</div>
				<div class="modal-footer">
					<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
					<button type="button" class="btn btn-primary" data-dismiss="modal" id="moredel">确定</button>
				</div>
			</div><!-- /.modal-content -->
		</div><!-- /.modal -->
	</div>
	
</div>
<script type="text/javascript">



console.log("123");
var usp=$("#usp").val();
var uid=$("#ex").val();
console.log(uid);

var currentPage=1;
    $(function(){
    	
    	//审批人下拉框
    	getExuser();
    	function getExuser(){
			$.ajax({
				url:"../showTr/findExuser",
				type:"post",
				dataType:"json",
				
				success:function(result){
					console.log(result.users);
					$("#ex").html("");
					$("#ex").append("<option value='0' selected='selected'>请选择审批人</option>")
	   			 	$.each(result.users,function(inx,ele){
	   			 		$("#ex").append(
							"<option value='"+ele.uid+"'>"+ele.uname+"</option>"
						 )
	   			 	})
				}
			})
		};
    	
    	
    	//删除  批量删除
    	$(document).on('click','#moredel',function(){
    		obj=document.getElementsByName("m");
    		check_val=[];
    		var str="";
    		for(i in obj){
    			if(obj[i].checked){
    				str+=obj[i].value+","
    				check_val.push(obj[i].value);
    				
    			}
    		}
    		console.log(str)
    		if(str==''){
    			alert("您选择的数据未审批或者您还没有选择数据！！！！！");
    		}else{
    			$.ajax({
    				url:'../showTr/deleteMore',
    				data:{'str':str},
    				dataType:'json',
    				type:'post',
    				success:function(res){
    					alert("删除成功");
    					getLea();
    				}
    			})
    		}
    		
    	});
    	
    	getLea(usp);
    	console.log("456");
    	
    	function getLea(){
    		console.log(usp);
    		console.log(uid);
    		
    		$.ajax({
        		url:"../showTr/showTrip",
        		type:"post",
        		data:{"usp":usp,"uid":uid,"currentPage":currentPage},
        		dataType:"json",
        		
        		success:function(result){
        			console.log(result);
        			var status=null;
        			var handle=null;
        			 $("#tr1").html("");
        			 $.each(result.trSecs,function(inx,ele){
        				 console.log(ele.deptname);
        				 if(ele.tr_status==0){
        					 status="未审批";
        					 handle="<a href='javascript:void(0)' id='aa'>审批</a><input type='hidden' value='"+ele.tr_id+"' id='hid'/>";
        					 $("#tr1").append(
          							"<tr class='warning'><td><input type='checkbox' name='wm' id='wm' value='"+ele.tr_id+"'/></td><td>"+(inx+1)+"</td><td><a href='javascript:void(0)' id='aa1'>"+ele.tr_applyuser+"</a><input type='hidden' value='"+ele.tr_id+"' id='hid'/></td><td>"+ele.deptname+"</td><td>"+ele.tr_time+"</td><td>"+ele.tr_start+"</td><td>"+status+"</td><td>"+ele.uname+"</td><td>"+handle+"</td></tr>"
          					 )
        				 }else if(ele.tr_status==1){
        					 status="审批通过";
        					 handle="<a href='javascript:void(0)' id='del'>删除</a><input type='hidden' value='"+ele.tr_id+"' id='hid'/>";
        					 $("#tr1").append(
        							 "<tr class='warning'><td><input type='checkbox' name='m' value='"+ele.tr_id+"'/></td><td>"+(inx+1)+"</td><td><a href='javascript:void(0)' id='aa1'>"+ele.tr_applyuser+"</a><input type='hidden' value='"+ele.tr_id+"' id='hid'/></td><td>"+ele.deptname+"</td><td>"+ele.tr_time+"</td><td>"+ele.tr_start+"</td><td>"+status+"</td><td>"+ele.uname+"</td><td>"+handle+"</td></tr>"
          					 )
        				 }else{
        					 status="审批不通过";
        					 handle="<a href='javascript:void(0)' id='del'>删除</a><input type='hidden' value='"+ele.tr_id+"' id='hid'/>";
        					 $("#tr1").append(
          							"<tr class='error'><td><input type='checkbox' name='m' value='"+ele.tr_id+"'/></td><td>"+(inx+1)+"</td><td><a href='javascript:void(0)' id='aa1'>"+ele.tr_applyuser+"</a><input type='hidden' value='"+ele.tr_id+"' id='hid'/></td><td>"+ele.deptname+"</td><td>"+ele.tr_time+"</td><td>"+ele.tr_start+"</td><td>"+status+"  <span style='font-size:6px;font-style:italic'>任务:"+ele.tr_work+"</span></td><td>"+ele.uname+"</td><td>"+handle+"</td></tr>"
          					 )
        				 }
        				 
        				 laypage({
       					  cont: $("#page"),  //容器
       					  pages: result.pages, //总页数
       					  curr:currentPage,     //当前页, 
       					  skin: 'molv', //皮肤
       					  skip:true, //支持跳页的功能
       					  last:'尾页',
       					  groups:3,  //多少页进行分组
       					  jump: function(obj, first){ //触发分页后的回调
       						currentPage = obj.curr;
       					    if(!first){   //一定要加此判断，否则初始时会无限刷新
       					      getLea();  //获取当前页
       					    }
       					  }
       					});
        			 })
        		}
        	})
    	};
    	
    	//条件查找点击事件
    	$("#btn").click(function(){
   		   usp=$("#inp").val();
   		   console.log(usp);
   		   uid=$("#ex").val();
   		   console.log(uid);
   		   getLea();
   		   
   	   });
    	
    	//审批点击事件
    	$(document).on('click','#aa',function(){
    		var tr_id=$(this).siblings("#hid").val();
    		console.log(tr_id);
    		$.ajax({
    			url:"../showTr/findTr",
    			type:"post",
    			data:{"tr_id":tr_id},
    			dataType:"json",
    			
    			success:function(result){
    				console.log(result);
    				console.log(result.trSec.tr_id);
    				$(".tr_id").val(result.trSec.tr_id)
    				$(".d1").html(result.trSec.tr_applyuser);
    				$(".d2").html(result.trSec.deptname);
    				$(".d3").html(result.trSec.tr_work);
    				$(".d4").html(result.trSec.tr_address);
    				$(".d5").html(result.trSec.tr_time);
    				$(".d6").html(result.trSec.tr_start);
    				$(".d7").html(result.trSec.ujob+" "+result.trSec.uname);
    				$(".d8").html(result.trSec.tr_reason);
    				$("#myModal").modal("show");
    			}
    		})
    	});
    	
    	//详细信息查看点击事件
    	$(document).on('click','#aa1',function(){
    		var tr_id=$(this).siblings("#hid").val();
    		console.log(tr_id);
    		$.ajax({
    			url:"../showTr/selectTr",
    			type:"post",
    			data:{"tr_id":tr_id},
    			dataType:"json",
    			
    			success:function(result){
    				console.log(result);
    				console.log(result.trSec.tr_id);
    				$(".tr_id").val(result.trSec.tr_id)
    				$(".td1").html(result.trSec.tr_applyuser);
    				$(".td2").html(result.trSec.deptname);
    				$(".td3").html(result.trSec.tr_work);
    				$(".td4").html(result.trSec.tr_address);
    				$(".td5").html(result.trSec.tr_time);
    				$(".td6").html(result.trSec.tr_tool);
    				$(".td7").html(result.trSec.tr_start);
    				$(".td8").html(result.trSec.tr_end);
    				$(".td9").html(result.trSec.ujob+" "+result.trSec.uname);
    				$(".td10").html(result.trSec.tr_reason);
    				$(".td11").html(result.status);
    				$("#selectTr").modal("show");
    			}
    		})
    	});
   
    	//删除点击事件，显示提示框
    	$(document).on('click','#del',function(){
    		var tr_id=$(this).siblings("#hid").val();
    		console.log(tr_id);
    		$("#trid").val(tr_id);
    		console.log($("#trid").val());
    		$("#deleteTr").modal("show");
    	});
    	
    	//删除提示框确定点击事件
    	$(document).on('click','#btn1',function(){
    		var tr_id=$("#trid").val();
    		console.log(tr_id);
    		
    		$.ajax({
    			url:"../showTr/deleteTr",
    			type:"post",
    			data:{"tr_id":tr_id},
    			dataType:"json",
    			
    			success:function(result){
    				if(result.res!=0){
    					$("#deleteTr").modal("hide");
    					alert("删除成功");
    					getLea();
    				}
    			}
    		})
    	});
    	    	
    });
    
    /*全选/反选触发函数*/
	function check_all(){
	     var del = document.getElementById("allChecked").checked;
	     var arrState = document.getElementsByName("m");
	    
	     for(var i = 0;i<arrState.length;i++){
	            arrState[i].checked = del;	            
	     }
	 }
</script>
</body>
</html>